<template>
  <div class="login">
    <div class="login-logo">
      <h1>广西师范大学法学院</h1>
      <h2>知识产权数字法学实验室</h2>
    </div>
    <div class="login-content">
      <img class="login-bg" src="@/assets/images/login_bg.png" />
      <div class="login-wrap">
        <div class="login-wrap-content">
          <div class="login-wrap_login">
            <p class="login_title">用户登录<i></i></p>
            <el-form label-position="left">
              <el-form-item size="small" label="账号" label-width="90px">
                <el-input v-model="userLogin.user_name"></el-input>
              </el-form-item>
              <el-form-item label="密码" label-width="90px" style="margin-bottom: 20px;">
                <el-input size="small" type="password" v-model="userLogin.password"></el-input>
              </el-form-item>
              <p style="margin-bottom: 20px;"><el-checkbox v-model="agree" label="同意服务条款" size="small" /></p>
              <el-form-item label-width="0px" class="login-btn">
                <el-button style="width: 100%;" type="primary" @click="handLogin">登录</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { useStore } from 'vuex';
import { ElMessage } from 'element-plus';
import { defineComponent, reactive, ref } from 'vue';

export default defineComponent({
  name: 'login',
  setup() {
    interface UserLogin {
      user_name: string;
      password: string;
    }
    const store = useStore();
    let loginActive = ref<string>('login');
    const agree = ref(true);
    const userLogin = reactive<UserLogin>({
      user_name: '',
      password: '',
    });
    const handLogin = async () => {
      const { user_name, password } = userLogin;
      if (!user_name || !password) {
        ElMessage.warning('请完善登录信息!');
        return;
      }
      await store.dispatch('user/userLogin', userLogin);
    };
    return {
      agree,
      loginActive,
      userLogin,
      handLogin,
    };
  },
});
</script>

<style lang="scss" scoped>
.login {
  width: 100%;
  height: 100%;
  float: left;
  background: linear-gradient(to top left, #dbe8fd, #bad2fa);
  background-size: 100%;
  position: relative;
  &-content {
    width: 1200px;
    height: 100%;
    position: relative;
    margin: 0 auto;
  }
  &-logo {
    position: absolute;
    left: 100px;
    top: 80px;
    cursor: pointer;
    text-shadow: rgba(0,0,0,0.3) 2px 2px 4px;
    h1 {
      margin: 0;
      font-size: 18px;
      font-weight: normal;
      color: #fbfcff;
      margin-bottom: 10px;
    }
    h2 {
      margin: 0;
      font-size: 22px;
      color: #fbfcff;
    }
  }
  &-bg {
    display: block;
    width: 920px;
    left: 0;
    top: calc(50% - 330px);
    position: absolute;
    z-index: 0;
  }
  &-wrap {
    position: absolute;
    width: 420px;
    height: auto;
    right: 0;
    top: 22%;
    padding: 10px 30px;
    box-shadow: 0px 0px 5px rgb(0, 0, 0, 10%);
    border: rgb(0, 0, 0, 9%) solid 1px;
    border-radius: 5px;
    z-index: 10;
    background: rgba(255, 255, 255, .4);
    .login_title {
      font-weight: normal;
      font-size: 20px;
      color: #040727;
      line-height: 50px;
      text-align: center;
      font-weight: 600;
      margin-bottom: 20px;
      position: relative;
      i {
        display: block;
        width: 34px;
        height: 4px;
        background: #2f66f2;
        position: absolute;
        bottom: 0;
        left: calc(50% - 17px);
        border-radius: 4px;
      }
    }
  }
  .login-btn {
    text-align: right;
  }
  .el-form-item {
    margin-bottom: 40px;
    flex-direction: column;
  }
  ::v-deep(.el-form-item__label) {
    line-height: 30px;
    font-size: 16px;
    color: #8a8d91;
    font-weight: normal;
    margin-bottom: 10px;
  }
  ::v-deep(.el-input__inner) {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    border-bottom: #a2b2c5 solid 2px;
    font-size: 14px;
    letter-spacing: 2px;
    &:focus {
      border-bottom: #2f66f2 solid 2px;
    }
    .login-btn {
      ::v-deep(.el-button) {
        width: 100%;
        background: #2f66f2;
      }
    }
  }
}
</style>
